import { Query } from '../../../../../Hooks/useQuery'
import { newSourceLayer, high_source } from './useMapSourceLayer'

export let isSearch = ref(true)
export function searchEventByDirver(map, address) {
  const { high_layer } = newSourceLayer(map)
  let service = {
    name: 'guanggu',
    layerId: 2
  }
  let where = `发生地点 like '%${address}%'`

  Query.queryByAttrSQL({
    where,
    service,
    callback: handleQuery
  })

  function handleQuery(features) {
    if (features) {
      high_source.addFeatures(features)
    } else {
      isSearch.value = true
      ElMessage({
        showClose: true,
        message: '您搜索的地名有误或者未出现紧急事件',
        type: 'warning',
        duration: 1000
      })
    }

    // event.value = features.map((item) => item.values_.values_)
  }

  return {
    high_layer
  }
}
